﻿// Copyright (c) Argo Zhang (argo@163.com). All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
// Website: https://www.blazor.zone or https://argozhang.github.io/

using Microsoft.AspNetCore.Components;
using SupperTreeSample.Shared.Data;

namespace SupperTreeSample.Shared.Components;

/// <summary>
/// Tree 组件
/// </summary>
public partial class SupperMenu
{
    [NotNull]
    private List<FoodDayNode>? Items { get; set; }

    [NotNull]
    private FoodDay? FoodDayElement { get; set; }

    protected override void OnInitialized()
    {
        base.OnInitialized();

        Items = FoodGenerator.GenerateDays();
    }

    /// <summary>
    /// 收起所有节点
    /// </summary>
    /// <returns></returns>
    public async Task CollapseAll()
    {
        // 收缩所有节点
        await FoodDayElement.ToggleAll(true);
    }

    /// <summary>
    /// 展开所有节点
    /// </summary>
    /// <returns></returns>
    public async Task ExpandAll()
    {
        // 展开所有节点
        await FoodDayElement.ToggleAll(false);
    }

    /// <summary>
    /// 收起所有节点
    /// </summary>
    /// <returns></returns>
    public async Task CollapseTimesAll()
    {
        // 收缩所有节点
        await FoodDayElement.ToggleAll(true, "time");
    }

    /// <summary>
    /// 展开所有节点
    /// </summary>
    /// <returns></returns>
    public async Task ExpandTimesAll()
    {
        // 展开所有节点
        await FoodDayElement.ToggleAll(false, "time");
    }

    /// <summary>
    /// 收起所有节点
    /// </summary>
    /// <returns></returns>
    public async Task CollapseMenusAll()
    {
        // 收缩所有节点
        await FoodDayElement.ToggleAll(true, "menu");
    }

    /// <summary>
    /// 展开所有节点
    /// </summary>
    /// <returns></returns>
    public async Task ExpandMenusAll()
    {
        // 展开所有节点
        await FoodDayElement.ToggleAll(false, "menu");
    }
}
